from models import execute, execute_with_commit, execute_tuple, execute_many


async def update_order_status(order_id: str) -> None:
    # 把到期的订单的状态由0变为-1
    await execute_with_commit('update `order` set status = -1 where order_id = %s', (order_id, ))
    # 查询此订单的所有商品对应的num数量
    _, skus_id = await execute_tuple('select num, sku_id from order_detail where oid = %s', (order_id, ))
    # 把对应的数量回到对应的sku商品中的库存中
    await execute_many('update good_sku set num = num + %s where id = %s', list(skus_id))
